package com.yeyks.app.controller.base.consumer;

import com.yeyks.app.annotation.LoadUserId;
import com.yeyks.common.ajax.AjaxResponseBody;
import com.yeyks.commonReference.service.consumer.UserCouponInfoService;
import com.yeyks.commonReference.utils.UserUtils;
import com.yeyks.consumer.dal.domain.UserInfo;
import com.yeyks.consumer.dto.UserCouponInfoDTO;
import com.yeyks.consumer.dto.UserCouponPushDTO;
import com.yeyks.consumer.dto.UserCouponResultDTO;
import com.yeyks.consumer.param.UserCouponInfoSelectUserCouponListParam;
import com.yeyks.consumer.param.coupon.UserCouponPushParam;
import com.yeyks.consumer.service.UserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Author fuchangshuai
 * @date 2019/3/26 4:27 PM
 */
@Api(tags = "用户优惠券接口", description = "用户优惠券")
@Slf4j
@RestController("appUserCouponInfoController")
@RequestMapping(value = "/app/user/coupon")
public class UserCouponInfoController {
    @Autowired
    private UserInfoService userInfoService;
    @Autowired
    private UserCouponInfoService userCouponService;

    /**
     * 根据一定条件查询当前用户的优惠券(V2)
     *
     * @param token
     * @param useStatus 优惠券状态, 默认1未使用，2已使用，3已过期
     * @param price     满减的价格
     * @param pageNum
     * @param pageSize
     * @return
     */
    @ApiOperation(value = "根据一定条件查询当前用户的优惠券(V2):v3.8", notes = "当需要获取满减券时传入price", response = UserCouponResultDTO.class)
    @PostMapping(value = "/list/V2")
    public AjaxResponseBody<Map<String, Object>> couponList(UserCouponInfoSelectUserCouponListParam param) {
        UserInfo userInfo = userInfoService.tokenUserInfo(param.getToken());
        param.setUserId(userInfo.getId());
        Map<String, Object> map = userCouponService.selectUserCouponList(param);
        return AjaxResponseBody.success(map);
    }

    /**
     * 获取推广充值获取的优惠券
     *
     * @param token
     * @return
     */
    @ApiOperation(value = "获取推广充值获取的优惠券", notes = "根据body里数据判断，为null代表没有", response = UserCouponInfoDTO.class)
    @ApiImplicitParam(paramType = "query", name = "token", value = "token", required = true, dataType = "String")
    @PostMapping(value = "/recommend/info")
    public AjaxResponseBody<UserCouponInfoDTO> couponList(@RequestParam(name = "token") String token) {
        UserInfo userInfo = userInfoService.tokenUserInfo(token);
        UserCouponInfoDTO userCouponInfoDTO = userCouponService.selectNewCoupon(userInfo);
        return AjaxResponseBody.success(userCouponInfoDTO);
    }

    @ApiOperation(value = "v3.8获取推送优惠券", notes = "根据body里数据判断，为null代表没有", response = UserCouponPushDTO.class)
    @PostMapping(value = "/push")
    public AjaxResponseBody<UserCouponPushDTO> selectCouponPush(@LoadUserId UserCouponPushParam param) {

        UserCouponPushDTO userCouponPushDTO = userCouponService.selectCouponPush(param);

        return AjaxResponseBody.success(userCouponPushDTO);
    }


}
